package sopt.dev.activity;

import java.util.ArrayList;

import sopt.dev.R;
import sopt.dev.data.Setting;
import sopt.dev.data.SettingAdapter;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class SettingActivity extends Activity implements OnItemClickListener {

	private ListView listview;
	private TextView tv_title;
	private TextView tv_info;
	private ArrayList<Setting> set = new ArrayList<Setting>();

	/** Called when the activity is first created. */
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting_activity);
		
		tv_info = (TextView) findViewById(R.id.setting_tv_info);

		addSetting(new Setting("국가", "한국"));
		addSetting(new Setting("버전정보", "v0.1"));
		addSetting(new Setting("공지사항"));
		addSetting(new Setting("통계"));

		SettingAdapter adapter = new SettingAdapter(this,
				R.layout.setting_item, set);
		listview = (ListView) findViewById(R.id.setting_listview);
		listview.setOnItemClickListener(this);
		listview.setAdapter(adapter);

	}
	
	private void addSetting(Setting newSetting) {
		set.add(newSetting);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
		switch (position) {
		case 0:
			showDialog(1);
			break;

		case 1:

			break;

		case 2:

			break;

		case 3:

			break;

		default:
			break;
		}

	}

	protected Dialog onCreateDialog(int id) {
		AlertDialog.Builder builder = new AlertDialog.Builder(
				SettingActivity.this);
		builder.setTitle("국가 선택");
		builder.setItems(R.array.nation, new DialogInterface.OnClickListener() {
			// 리스트 목록 클릭 이벤트
			@Override
			public void onClick(DialogInterface dialog, int which) {
				tv_info.setText(getResources().getStringArray(R.array.nation)[which]);
			}

		});

		builder.setPositiveButton("확인", null);
		builder.setNegativeButton("취소", null);
		return builder.create();
	}
}
